const { app, BrowserWindow ,Menu} = require('electron');//引入electron
let win;
let windowConfig = {
    width: 1200,
    height: 800,
    backgroundColor: '#2e2c29',
    webPreferences: {
        nodeIntegration: true, // 是否集成 Nodejs,把之前预加载的js去了，发现也可以运行
      }
};//窗口配置程序运行窗口的大小
const winURL = process.env.NODE_ENV == 'dev'
  ? `http://127.0.0.1:8080`
  : `file://${__dirname}/index.html`
function createWindow() {
    const menu = Menu.buildFromTemplate(template)
    Menu.setApplicationMenu(menu) // 设置菜单部分
    win = new BrowserWindow(windowConfig);//创建一个窗口
    win.loadURL(winURL);//在窗口内要展示的内容index.html 就是打包生成的index.html
    win.on('close', () => {
        //回收BrowserWindow对象
        win = null;
    });
    process.env.NODE_ENV == 'dev' ? win.webContents.openDevTools = true : win.webContents.openDevTools = false;
    win.on('resize', () => {
        win.reload();
    })
}
app.on('ready', createWindow);
app.on('window-all-closed', () => {
    app.quit();
});
app.on('activate', () => {
    if (win == null) {
        createWindow();
    }
});

let template = [
    {
        label: '系统',
        submenu: [{
            label:"设置",
            click:()=>{
                win.webContents.send("on-menu-change","/setting")
            }
        },{
            label: '注销',
            click:()=>{
                win.webContents.send("on-menu-change","/logout");
            },
        }, {
            label: '退出',
            accelerator: 'alt+F4',
            role: 'quit'
        }]
    },{
        label:"任务",
        submenu:[
            {
                label:"添加任务",
            },{
                label:"管理任务",
            }
        ]
    },{
        label:"用户",
        submenu:[
            {
                label:"管理用户",
            }
        ]
    },{
        label:"财务",
        submenu:[
            {
                label:"流水查询"
            }
        ]
    }
];

